package com.example.demo.service;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.nio.ByteBuffer;
import java.util.ArrayList;

/**
 * @author ：roc.zou
 * @date ：Created in 2022/5/4 18:38
 * @description ：
 */
@Component
public class DirectBuffer {
    private static final int _10Mb = 1024 * 1024 * 10;
    private static ArrayList<Object> list = new ArrayList<>();

    @PostConstruct
    public void test() {
        new Thread(() -> {
            while (true) {
                try {
                    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(_10Mb);
                    while (byteBuffer.position() < 1024 * 1024 * 9) {
                        byteBuffer.putChar('a');
                        byteBuffer.putChar('b');
                        byteBuffer.putChar('c');
                    }
                    list.add(byteBuffer);
//                    byteBuffer.clear();
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }
}
